<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <style>
    .box {
      display: flex;
      justify-content: center;
      align-items: center;
      width: 200px;
      height: 200px;
      background-color: orange;
    }

    .box span {
      width: 100px;
      height: 100px;
      background-color: red;
    }
  </style>
</head>
<body>
  
  <div class="box">
    <span></span>
  </div>

  <script>
    var boxEl = document.querySelector(".box")
    var spanEl = document.querySelector("span")

    // mouseenter和mouseleave
    // 不支持冒泡：进入子元素依然属于在该元素内，子元素触发的事件不会冒泡到父元素
    // 浏览器会给每一个嵌套层级中的元素发送一个mouseenter事件
    boxEl.onmouseenter = function() {
      console.log("box onmouseenter")
    }
    boxEl.onmouseleave = function() {
      console.log("box onmouseleave")
    }

    spanEl.onmouseenter = function() {
      console.log("span onmouseenter")
    }
    spanEl.onmouseleave = function() {
      console.log("span onmouseleave")
    }

    // mouseover和mouseout
    // 支持冒泡：进入元素的子元素时
    // 先调用父元素的mouseout
    // 再调用子元素的mouseover
    // 因为支持冒泡，所以会将mouseover传递到父元素中；
    // boxEl.onmouseover = function() {
    //   console.log("box onmouseover")
    // }
    // boxEl.onmouseout = function() {
    //   console.log("box onmouseout")
    // }

  </script>

</body>
</html>